package com.ks.winterwarmimage;

import android.app.Application;
import android.content.Context;

import com.ks.winterwarmimage.database.DatabaseManager;
import com.ks.winterwarmimage.utils.Constants;
import com.ks.winterwarmimage.wifi.WiFiTools;

public class WinterWarmImageApplication extends Application {
    private static final String TAG="LampApplication";
    public static Context appContext;
    /**存储前一次的WiFi*/
    public static WiFiTools.WiFi lastWifi;
    private WiFiTools wifiTools;

    @Override
    public void onCreate() {
        super.onCreate();
        appContext=getApplicationContext();
        openOrCreateDatabase();   //打开或创建数据库
        wifiTools=new WiFiTools(this);
        lastWifi=wifiTools.getConnectedWifi();    //将当前WiFi保存为上一次的WiFi，为APP退出自动切换使用
    }

    /**打开或创建数据库*/
    private void openOrCreateDatabase() {
        //创建并打开数据库
        DatabaseManager.createDatabase(this);
        createTable();       //创建表单
    }
    /**创建表单*/
    private void createTable(){
        if(DatabaseManager.database!=null){
            if(!DatabaseManager.existsTable(Constants.TABLE_DEV)){
                String SQL = "CREATE TABLE " + Constants.TABLE_DEV + " (\n" +
                        "--灯ID（模块的全球Mac）\n" +
                        Constants.KEY_MAC_ID+" CHAR(20) PRIMARY KEY,\n" +
                        "--灯组名称\n" +
                        Constants.KEY_DEV_NAME+" CHAR(80),\n" +
                        "--账户\n" +
                        Constants.KEY_ACCOUNT_ID+" CHAR(8)\n" +
                        ")";
                DatabaseManager.database.execSQL(SQL);
            }
        }
    }
}
